import format from "date-fns/format"

export function numWithCommas(num) {
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}

export function numWithPercent(num, digit = 2) {
  return (num * 100).toFixed(digit) + "%"
}

export function numWithDecimals(num, digit = 2) {
  if(num == null) return "-"
  return Number(num).toFixed(digit)
}

export default {
  dateFormat: format,
  numWithCommas,
  numWithPercent,
  numWithDecimals,
}
